package dao

import (
	"fmt"
	"hft/Http/Models/request"
	utils "hft/Http/Utils"

	"gorm.io/gorm"
)

type GetActive struct{}

func (g *GetActive) Name(name string) func(db *gorm.DB) *gorm.DB {

	return func(db *gorm.DB) *gorm.DB {
		if utils.DeleteStringSpace(name) == "" {
			return db
		} else {
			return db.Where("name LIKE ?", fmt.Sprintf("%v%%", name))
		}
	}
}

func (g *GetActive) GetActiveList(RegionLink string, paginate *request.ActiveSearchReq, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	var nameLike = fmt.Sprintf("%v%%", paginate.Name)
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("lou_pan_id = ?", paginate.LouPanId).Scopes(g.Name(nameLike)).Where("region_link LIKE ?", fmt.Sprintf("%v%%", RegionLink)).Where(paginate.ActiveSearchInfo).Scopes(Paginate(Page(paginate.Page), db)).Order("create_time desc").Scopes(BaseDao.CreateTime(db, paginate.CreateTime))
	}
}

var GetActiveDao = new(GetActive)
